package com.awspaas.user.apps.publicservice.util;

import com.actionsoft.bpms.commons.database.RowMap;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author:Lizj
 * @create: 2022-10-13 21:51
 * @Description: list<RowMap>数据比对工具类，多个参数
 */
public class RowMapListUtils {

    /**
     * @methodName: 获取交集
     * @param:
     * @return:
     * @description:
     * @auther: Lizj
     * @date: 2022/10/13 21:53
     */
    public List<RowMap> sameList(List<RowMap> oldList, List<RowMap> newList, String param1, String param2, String param3) {
        List<RowMap> resultList = newList.stream()
                .filter(item -> oldList.stream().map(e -> e.getString(param1) + "&" + e.getString(param2) + "&" + e.getString(param3))
                .collect(Collectors.toList()).contains(item.getString(param1) + "&" + item.getString(param2) + "&" + item.getString(param3)))
                .collect(Collectors.toList());
        return resultList;
    }

    /**
     * @methodName: 获取差集
     * @param:
     * @return:
     * @description:
     * @auther: Lizj
     * @date: 2022/10/13 22:12
     */
    public List<RowMap> diffList(List<RowMap> firstList, List<RowMap> secondList, String param1, String param2, String param3) {
        List<RowMap> resultList = firstList.stream()
                .filter(item -> !secondList.stream().map(e -> e.getString(param1) + "&" + e.getString(param2) + "&" + e.getString(param3))
                .collect(Collectors.toList()).contains(item.getString(param1) + "&" + item.getString(param2) + "&" + item.getString(param3)))
                .collect(Collectors.toList());
        return resultList;
    }

}
